import Vuex from 'vuex'
import Vue from "vue";
Vue.use(Vuex)
// 该文件用于创建 vuex 中最核心的 store
const actions = {
    jia(context, value){
        console.log('JIA');
        context.commit('JIA',value)
    },
    jiaOdd(context, value){
        if(context.state.sum%2==1){
            console.log('JIA_ODD');
            context.commit('JIA',value)
        }
    },
    jiaWait(context, value){
        console.log('JIA_WAIT');
        setTimeout(()=>{
            // this.sum = this.sum+this.n;
            context.commit('JIA',value)
        }, 500);

    },
    jian(context, value){
        console.log('JIAN');
        context.commit('JIAN',value)
    }
}
const mutations = {
    JIA(state, value){
        console.log('state JIA');
        state.sum = state.sum + value;
    },

    JIAN(state, value){
        console.log('state JIAN');
        state.sum = state.sum - value;
    }
}
const state = {
    sum:0,
    school: "尚硅谷",
    subjects: "前端"
}

const getters = {
    bigSum(state){
        return state.sum*10;
    }
}

const store = new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})

export default store;
